﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Models;


namespace DAL
{
    /// <summary>
    /// 支付方式
    /// </summary>
    public class payDAL
    {
        //支付方式查询
        public static DataTable selectPay()
        {
            string sql = "select * from tb_Pay";
            return SqlDBHelper.GetDataTable(sql);
        }
        //查询数据条数
        public static object dataNum()
        {
            string sql = "select count(*) from tb_Pay";
            return SqlDBHelper.ExecuteScalar(sql);
        }
        //支付方式添加
        public static int payAdd(string name)
        {
            string sql = "insert into tb_Pay(PayName) values(@PayName)";
            SqlParameter[] para = {
            new SqlParameter("@PayName",name),
            };
            return SqlDBHelper.ExecuteNonQuery(sql,para);
        }
        //支付方式添加判断重复
        public static object payCF(string name)
        {
            string sql = "select * from tb_Pay where PayName='" + name + "'";
            return SqlDBHelper.ExecuteScalar(sql);
        }
        //支付方式修改
        public static int updatePay(Pay p) {
            string sql = "update tb_Pay set PayName=@PayName where PayID=@PayID";
            SqlParameter[] para = { 
            new SqlParameter("@PayID",p.PayID),
            new SqlParameter("@PayName",p.PayName),
            };
            return SqlDBHelper.ExecuteNonQuery(sql,para);
        }
        //支付方式查询
        public static DataTable payCX(string name) {
            string sql = "select * from tb_Pay where PayName like'%"+name+"%'";
            return SqlDBHelper.GetDataTable(sql);
        }
        //支付方式删除
        public static int delete(int id)
        {
            string sql = "delete from tb_Pay where PayID=" + id;
            return SqlDBHelper.ExecuteNonQuery(sql);
        }
        //下拉框
        public static List<Pay> liXlk()
        {
            string sql = "select * from tb_Pay";
            SqlDataReader dr = SqlDBHelper.GetReader(sql);
            List<Pay> lis = new List<Pay>();
            while (dr.Read())
            {
                lis.Add(new Pay()
                {
                    PayID = Convert.ToInt32(dr["PayID"]),
                    PayName = dr["PayName"].ToString()
                });
            }
            dr.Close();
            return lis;
        }
        //支付判断重复
        public static object orderPay(string bh)
        {
            string sql = "select Zf from tb_Order where Ordertitle="+ bh;
            return SqlDBHelper.ExecuteScalar(sql);
        }
    }
}
